var Drag = {
	obj : null,
	init : function(o) {
		o.onmousedown = Drag.start;

		if (isNaN(parseInt(o.style.left)))
			o.style.left = "0px";
		if (isNaN(parseInt(o.style.top)))
			o.style.top = "0px";
		if (isNaN(parseInt(o.style.right)))
			o.style.right = "0px";
		if (isNaN(parseInt(o.style.bottom)))
			o.style.bottom = "0px";
	},

	/**
	 * add 2010
	 */
	initDivs : function(ids) {
		if (ids != null && ids.length > 0) {
			for (i = 0; i < ids.length; i++) {
				var element = document.getElementById(ids[i]);
				Drag.init(element);
				//element.style.left = Math.random() * Drag.init(element);
			}
		}
	},

	start : function(e) {
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.style.top);
		var x = parseInt(o.style.left);

		o.lastMouseX = e.clientX;
		o.lastMouseY = e.clientY;

		document.onmousemove = Drag.drag;
		document.onmouseup = Drag.end;

		return false;
	},

	drag : function(e) {
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey = e.clientY;
		var ex = e.clientX;
		var y = parseInt(o.style.top);
		var x = parseInt(o.style.left);
		var nx, ny;

		nx = x + ex - o.lastMouseX;
		ny = y + ey - o.lastMouseY;

		Drag.obj.style["left"] = nx + "px";
		Drag.obj.style["top"] = ny + "px";
		Drag.obj.lastMouseX = ex;
		Drag.obj.lastMouseY = ey;

		return false;
	},

	end : function() {
		document.onmousemove = null;
		document.onmouseup = null;
		Drag.obj = null;
	},

	fixE : function(e) {
		if (typeof e == 'undefined')
			e = window.event;
		if (typeof e.layerX == 'undefined')
			e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined')
			e.layerY = e.offsetY;
		return e;
	}
};